# Definition for singly-linked list.
from typing import Optional


class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution:
    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:

        if head is None:
            return head
        if head.next is None:
            return head.next
        newHead = head.next
        nowNode = newHead
        dataNode = nowNode.next
        while dataNode is not None:
            if dataNode.val == 0:
                nowNode.next = dataNode.next
                dataNode = dataNode.next
                nowNode = nowNode.next
            else:
                nowNode.val += dataNode.val
                print(nowNode.val)

            if dataNode is not None:
                dataNode = dataNode.next
        # 最后置空
        if nowNode is not None:
            nowNode.next = None
        return newHead
